﻿using System;
using System.Data;
using System.Collections;
using System.Text.RegularExpressions;
using System.Text;
using System.Web.Caching;

using LTJ.Common;
using LTJ.Data;
using LTJ.Config;
using LTJ.Entity;
using LTJ.Common.Generic;
using LTJ.Cache;

namespace LTJ.FrameWork
{
    /// <summary>
    /// 公司信息操作
    /// </summary>
    public class Companys
    {
        /// <summary>
        /// 创建企业信息
        /// </summary>
        public static int CreateCompany(CompanyInfo cinfo)
        {
            return Data.DataProvider.Companys.CreateCompany(cinfo);
        }

        /// <summary>
        /// 根据查询条件获取企业数量
        /// </summary>
        public static int GetCompanyCount(string querystring)
        {
            return Data.DataProvider.Companys.GetCompanyCountByCondition(querystring);
        }

        /// <summary>
        /// 企业数据分页操作
        /// </summary>
        public static DataTable GetCompanyListByPage(int pageindex, int pagesize, string condition,string orderstr)
        {
            return Data.DataProvider.Companys.GetCompanyPageList(pageindex, pagesize, condition,orderstr);
        }

        /// <summary>
        /// 获取企业信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static CompanyInfo GetCompanyByID(int id)
        {
            return Data.DataProvider.Companys.GetCompanyInfo(id);
        }

        /// <summary>
        /// 更新企业信息
        /// </summary>
        public static void UpdateCompany(CompanyInfo cinfo)
        {
            Data.DataProvider.Companys.UpdateCompany(cinfo);
        }

        /// <summary>
        /// 删除企业信息
        /// </summary>
        /// <param name="ids">企业id组合</param>
        /// <returns></returns>
        public static int DelCompany(string ids)
        {
            return LTJ.Data.DataProvider.Companys.DelCompany(ids);
        }

        /// <summary>
        /// 判断企业是否存在
        /// </summary>
        public static int IsExistCompany(string companyname)
        {
            return LTJ.Data.DataProvider.Companys.IsExistCompany(companyname);
        }

        /// <summary>
        /// 获取企业基本查询条件
        /// </summary>
        /// <param name="cntitle">中文关键字</param>
        /// <param name="entitle">英文关键字</param>
        /// <param name="isVaild">是否需要企业有效验证</param>
        /// <returns>条件语句</returns>
        public static string GetCompanySearchCondition(string cntitle, string entitle, bool isVaild)
        {
            string strWhere = "";

            if (isVaild) strWhere = " status = 1 ";
            else strWhere = "1=1";
            if (!string.IsNullOrEmpty(cntitle)) strWhere += " AND cname like '%" + cntitle + "%'";
            if (!string.IsNullOrEmpty(entitle)) strWhere += " AND ecname like '%" + entitle + "%'";

            return strWhere;
        }

        /// <summary>
        /// 停止企业合作
        /// </summary>
        public static bool PauseCorp(string ids)
        {
            return UpdateCorpStatus(ids, 0);
        }
        /// <summary>
        /// 开启企业合作
        /// </summary>
        public static bool StartCorp(string ids)
        {
            return UpdateCorpStatus(ids, 1);
        }

        /// <summary>
        /// 更改企业状态
        /// </summary>
        public static bool UpdateCorpStatus(string ids, int status)
        {
            return LTJ.Data.DataProvider.Companys.UpdateCorpStatus(ids, status);
        }

        /// <summary>
        /// 设置企业积分
        /// </summary>
        /// <param name="cid"></param>
        /// <param name="scores"></param>
        public static int SetCorpScore(int cid, int scores)
        {
            return Data.DataProvider.Companys.SetCorpScore(cid, scores);
        }
    }
}
